package com.liugan.magic.utils;

import org.loon.framework.android.game.action.sprite.Animation;
import org.loon.framework.android.game.core.LSystem;

import android.util.Log;
import android.widget.Toast;

import com.liugan.magic.Constants;
import com.liugan.magic.actor.Illusionist;
import com.liugan.magic.actor.base.BaseActor;

public class  TransFormer {
	
	/**  标记为其他种类
	 * @param actor
	 */
	public static void transformerToother(Illusionist magic,BaseActor actor){
		magic.istransform=true;
		actor.setVisible(false);
		magic.ct.setCT(actor.ct);
		magic.setAnimation(AnimationUtils.getinstance().transformer);
		AnimationUtils.getinstance().transformer.start();
	}
	/**  标记为魔术师 还原
	 * @param actor
	 */
	public static void transformerTomagic(Illusionist magic){
		magic.istransform=true;
		magic.ct.setCT("magic", 0, 10, 1, 4, -15,0,0);//设定属性
		int temY=173;
		magic.offsetXY.y-=temY;
		magic.totalXY.y-=temY;
		magic.setLocation(magic.offsetXY.x, magic.offsetXY.y+magic.getHeight());
		magic.setAnimation(AnimationUtils.getinstance().transformer);
		AnimationUtils.getinstance().transformer.start();
	}
	
	/** 根据actor类型设置动画
	 * 
	 */
	public static void setState(BaseActor actor){
		Illusionist magicactor =(Illusionist)actor;
		//是否在运行"一次动画"
		if (magicactor.istransform){
			if (magicactor.getAnimation().getCurrentFrameIndex()==(magicactor.getAnimation().getTotalFrames()-1)){
				magicactor.istransform=false;
			}
			return;
		}
		
		//魔术师的动作
		if ("magic".equals(actor.ct.Actortype)){
			//向左右走 面向左右站立
			if (magicactor.isOnGround()){//y方向为零,走路
				if (magicactor.getVx()<0){//左
					magicactor.setAnimation(true);
					magicactor.setAnimation(AnimationUtils.getinstance().leftrunanimation);
					magicactor.isdir="left";
				}else if (magicactor.getVx()>0){//右
					magicactor.setAnimation(true);
					magicactor.setAnimation(AnimationUtils.getinstance().rightrunanimation);
					magicactor.isdir="right";
				}else{
					if (magicactor.isdir.equals("left")){
						magicactor.setAnimation(true);
						magicactor.setAnimation(AnimationUtils.getinstance().leftstandanimation);
						magicactor.isdir="left";
					}else if(magicactor.isdir.equals("right")){
						magicactor.setAnimation(true);
						magicactor.setAnimation(AnimationUtils.getinstance().rightstandanimation);
						magicactor.isdir="right";
					}else{
						magicactor.setAnimation(true);
						magicactor.setAnimation(AnimationUtils.getinstance().rightrunanimation);
						magicactor.isdir="right";
				}}
			}else{//跳动
				if (magicactor.isdir.equals("left")){
					magicactor.setAnimation(true);
					magicactor.setAnimation(AnimationUtils.getinstance().jumpanimation_left);
					magicactor.isdir="left";
				}else{
					magicactor.setAnimation(true);
					magicactor.setAnimation(AnimationUtils.getinstance().jumpanimation);
					magicactor.isdir="right";
				}
			}
		}
		
		//蝴蝶的动作
		if ("butterfly".equals(actor.ct.Actortype)){
			magicactor.setAnimation(true);
			magicactor.setAnimation(AnimationUtils.getinstance().butterflya);
			if (magicactor.getVx()<0){//左
				magicactor.isdir="left";
			}else{
				magicactor.isdir="right";
			}
		}
		
		//兔子的动作
		if ("rabbit".equals(actor.ct.Actortype)){
			//向左右走 面向左右站立
			if (magicactor.isOnGround()){//y方向为零,走路
				if (magicactor.getVx()<0){//左
					magicactor.setAnimation(true);
					magicactor.setAnimation(AnimationUtils.getinstance().rlra);
					magicactor.isdir="left";
				}else if (magicactor.getVx()>0){//右
					magicactor.setAnimation(true);
					magicactor.setAnimation(AnimationUtils.getinstance().rrra);
					magicactor.isdir="right";
				}else{
					if (magicactor.isdir.equals("left")){
						magicactor.setAnimation(true);
						magicactor.setAnimation(AnimationUtils.getinstance().rlsa);
					}else{
						magicactor.setAnimation(true);
						magicactor.setAnimation(AnimationUtils.getinstance().rrsa);
						magicactor.isdir="right";
				}}
			}else{
				if (magicactor.isdir.equals("left")){
					magicactor.setAnimation(false);
					magicactor.setImage(AnimationUtils.getinstance().rljump);
				}else{
					magicactor.setAnimation(false);
					magicactor.setImage(AnimationUtils.getinstance().rrjump);
				}
			}
		}
		//青蛙的动作
		if ("frog".equals(actor.ct.Actortype)){
			//向左右走 面向左右站立
			if (magicactor.isOnGround()){//y方向为零,走路
				if (magicactor.getVx()<0){//左
					magicactor.setAnimation(true);
					magicactor.setAnimation(AnimationUtils.getinstance().flr);
					magicactor.isdir="left";
				}else if (magicactor.getVx()>0){//右
					magicactor.setAnimation(true);
					magicactor.setAnimation(AnimationUtils.getinstance().frr);
					magicactor.isdir="right";
				}else{
					if (magicactor.isdir.equals("left")){
						magicactor.setAnimation(true);
						magicactor.setAnimation(AnimationUtils.getinstance().fls);
					}else{
						magicactor.setAnimation(true);
						magicactor.setAnimation(AnimationUtils.getinstance().frs);
						magicactor.isdir="right";
				}}
			}else{
				if (magicactor.isdir.equals("left")){
					magicactor.setAnimation(false);
					magicactor.setImage(AnimationUtils.getinstance().fljump);
				}else{
					magicactor.setAnimation(false);
					magicactor.setImage(AnimationUtils.getinstance().frjump);
				}
			}
		}
		//狐狸的动作
		if ("fox".equals(actor.ct.Actortype)){
			//向左右走 面向左右站立
			if (magicactor.isOnGround()){//y方向为零,走路
				if (magicactor.getVx()<0){//左
					magicactor.setAnimation(true);
					magicactor.setAnimation(AnimationUtils.getinstance().fflr);
					magicactor.isdir="left";
				}else if (magicactor.getVx()>0){//右
					magicactor.setAnimation(true);
					magicactor.setAnimation(AnimationUtils.getinstance().ffrr);
					magicactor.isdir="right";
				}else{
					if (magicactor.isdir.equals("left")){
						magicactor.setAnimation(true);
						magicactor.setAnimation(AnimationUtils.getinstance().ffls);
					}else{
						magicactor.setAnimation(true);
						magicactor.setAnimation(AnimationUtils.getinstance().ffrs);
						magicactor.isdir="right";
				}}
			}else{
				if (magicactor.isdir.equals("left")){
					magicactor.setAnimation(false);
					magicactor.setImage(AnimationUtils.getinstance().ffljump);
				}else{
					magicactor.setAnimation(false);
					magicactor.setImage(AnimationUtils.getinstance().ffrjump);
				}
			}
		}
		
	}
	public static void setAnimation(BaseActor actor,Animation animation){
			actor.setAnimation(animation);
	}
}
